package com.rp.system.po;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Type;
import org.raptor.entity.BaseModel3;

/**
 * 角色
 * @author HuangJian
 *
 */
@Entity
@Table(name="RP_SYSTEM_ROLES")
public class Role extends BaseModel3 {

	private static final long serialVersionUID = 1422698214745991142L;
	
	private String name;					//角色名称
	private String remark;					//备注
	
	private String superRole;				//是否是超级管理员角色	
	
	//private List<User> users;				//对应用户
	private List<Authority> authorities;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getSuperRole() {
		return superRole;
	}

	public void setSuperRole(String superRole) {
		this.superRole = superRole;
	}

	/*@JsonIgnore
	@ManyToMany(mappedBy="roles")
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}*/
	
	@ManyToMany(
			fetch = FetchType.LAZY,
			cascade = {CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH})
	@JoinTable(
			name = "RP_SYSTEM_ROLE_AUTHORITY", 
			joinColumns = { @JoinColumn(name = "role_id") }, 
			inverseJoinColumns = { @JoinColumn(name = "authority_id") })
	public List<Authority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(List<Authority> authorities) {
		this.authorities = authorities;
	}

	/**
	 * 重写equals方法
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Role) {
			Role role = (Role) obj;
			if (role.getId().equals(this.getId())) {
				return true;
			}
		}
		return false;
	}
	
}
